
import * as vscode from 'vscode';
import { homedir } from 'os';
import { readFileSync } from 'fs';

export interface BasePathAndToken {
    basePath: string;
    token: string;
}

export const getBasePath = (): BasePathAndToken | null => {
    const infoPath = `${homedir}/.linksaas/local_api`;
    try {
        const line = readFileSync(infoPath).toString();
        const parts = line.split(" ");
        return {
            basePath: `http://${parts[0]}`,
            token: parts.length == 2 ? parts[1] : "",
        }
    } catch (e) {
        vscode.window.showErrorMessage("没有启动凌鲨客户端程序");
        console.log(e);
        return null;
    }
}